package com.rdgzs.framework.utilsTools;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtils {
	private Pattern pattern = null;
	private Matcher matcher = null;
	private final String emailPtn = "^['_a-z0-9-\\+]+(\\.['_a-z0-9-\\+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2}|aero|arpa|asia|biz|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|nato|net|org|pro|tel|travel|xxx)$";
	private final String mobilePtn = "^1[3,4,5,8]\\d{9}$";
	private final String passPtn = "^([\\!\\\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\_\\`\\{\\|\\}\\~\\|\\\\\\w]+$)";
	private final String nicknamePtn = "^[\u4e00-\u9fa5\\w-]*$";
	private final String lengthPtn = ".";

	public static void main(String args[]) {
		Pattern pattern = Pattern.compile("(\\w|\\p{Punct}){6,15}");
		System.out.println(pattern.matcher("!@#$sf\ntsdf").find());
	}

	public final static RegexUtils getInstance() {
		return new RegexUtils();
	}

	public final Boolean test(final String regex,final String input) {
		pattern = Pattern.compile(regex);
		matcher = pattern.matcher(input);
		return matcher.find();
	}

	public final Boolean testEmail(final String input) {
		pattern = Pattern.compile(emailPtn);
		matcher = pattern.matcher(input);
		return matcher.find();
	}

	public final Boolean testMobile(final String input) {
		pattern = Pattern.compile(mobilePtn);
		matcher = pattern.matcher(input);
		return matcher.find();
	}

	public final Boolean testPassword(final String input) {
		pattern = Pattern.compile(passPtn);
		matcher = pattern.matcher(input);
		return matcher.find();
	}

	public final Boolean testPasswordLen(final String input,final Integer min,final Integer max) {
		return this.testLengthArea(input, min, max) && this.testPassword(input);
	}

	public final Boolean testNickname(final String input) {
		pattern = Pattern.compile(nicknamePtn);
		matcher = pattern.matcher(input);
		return matcher.find();
	}

	public final Boolean testNicknameLen(final String input,final Integer min,final Integer max) {
		return this.testLengthArea(input, min, max) && this.testNickname(input);
	}

	public final Boolean testLengthArea(final String input,final Integer min,final Integer max) {
		pattern = Pattern.compile(lengthPtn + "{" + min + "," + max + "}");
		matcher = pattern.matcher(input);
		return matcher.find();
	}

}